package com.gitee.simons.common.utils;

import com.gitee.simons.common.bean.SmsSendResponse;
import com.google.gson.Gson;
import org.apache.http.Consts;
import org.apache.http.client.fluent.Form;
import org.apache.http.client.fluent.Request;

import java.io.IOException;

/**
 * @Author: wangyq
 * @Date: 2019/3/25 11:42
 * @Description: 短信接口
 */
public class SmsUtil {

    private static Gson gson = new Gson();

    public static SmsSendResponse postSendSms(String phoneNumbers, String templateParam) throws IOException {
        SmsSendResponse ssr = new SmsSendResponse();
        String result = Request.Post("http://mediaroom.sunmnet.com:8899/action/mediaroom/pubserver/smsAction/sendSms")
                .addHeader("X-Custom-header", "stuff")
                .bodyForm(Form.form().add("phone", phoneNumbers).add("template", templateParam).build(), Consts.UTF_8)
                .execute().returnContent().asString();
        if (!"".equals(result)) {
            ssr = gson.fromJson(result, SmsSendResponse.class);
        }
        return ssr;
    }

    public static void main(String[] args) throws IOException {
        System.out.println(postSendSms("13247548436","您好！您的验证码为：252554，若非本人操作，请忽略此短信。"));
    }
}
